<template>
  <div>
    <van-nav-bar
      :z-index="999"
      :fixed="true"
      left-arrow
      @click-left="onClickLeft"
      :placeholder="true"
      title="查看订单"
    ></van-nav-bar>

    <div style="background:#fff;">
      <!-- 是否是本地 -->

      <van-cell-group>
        <van-cell title="驾驶人来源" :value="radio" />
      </van-cell-group>

      <!-- 申请类型 -->

      <van-cell-group>
        <van-cell title="申请类型" :value="type" />
      </van-cell-group>

      <!-- 现有驾照 -->
      <van-cell-group>
        <van-cell title="现有驾照" :value="drivingLicence" />
      </van-cell-group>
      <!-- end -->

      <!-- 选择驾校 -->
      <van-cell-group>
        <van-cell title="选择驾校" :value="ChooseSt" />
      </van-cell-group>
      <!-- end -->

      <!-- 选择教练 -->
      <van-cell-group>
        <van-cell title="选择教练" :value="coach" />
      </van-cell-group>
      <!-- end -->

      <!-- 准驾车型 -->
      <van-cell-group>
        <van-cell title="准驾车型" :value="override" />
      </van-cell-group>
      <!-- end -->

      <!-- 班型 -->
      <van-cell-group>
        <van-cell title="班型" :value="banks" />
      </van-cell-group>
      <!-- end -->

      <!-- 姓名 -->
      <van-cell-group>
        <van-cell title="姓名" :value="text" />
      </van-cell-group>
      <!-- end -->

      <!-- 国籍 -->
      <van-cell-group>
        <van-cell title="国籍" :value="nationality" />
      </van-cell-group>

      <!-- 证件类型 -->
      <van-cell-group>
        <van-cell title="证件类型" :value="papersType" />
      </van-cell-group>
      <!-- end -->

      <!-- 证件号码 -->
      <van-cell-group>
        <van-cell title="证件号码" :value="IDCard" />
      </van-cell-group>
      <!-- end -->

      <!-- 性别 -->
      <van-cell-group>
        <van-cell title="性别" :value="set" />
      </van-cell-group>
      <!-- end -->

      <!-- 出生年月 -->
      <!-- @click="showData" -->

      <van-cell-group>
        <van-cell title="出生年月" :value="years" />
      </van-cell-group>

      <!-- 身份证地址 -->
      <van-cell-group>
        <van-cell title="身份证地址" :value="site" />
      </van-cell-group>
      <!-- end -->

      <!-- 居住地 -->
      <!-- @click="showPopup" -->
      <van-cell-group>
        <van-cell title="居住地" :value="building" />
      </van-cell-group>

      <!-- 居住证号 -->
      <van-cell-group>
        <van-cell title="居住证号" :value="residencePermit" />
      </van-cell-group>

      <!-- end -->

      <!-- 居住证签发时间 -->
      <van-cell-group>
        <van-cell title="居住证签发时间" :value="cardTime" />
      </van-cell-group>
      <!-- end -->

      <!-- 暂住证 -->
      <!-- @click="showData" -->
      <van-cell-group>
        <van-cell title="暂住证到期时间" :value="stayExpire" />
      </van-cell-group>
      <!-- end -->

      <!-- 报名时间 -->
      <!-- @click="showData" -->
      <van-cell-group>
        <van-cell title="报名时间" :value="signUpTime" />
      </van-cell-group>

      <!-- end -->

      <!-- 招生来源 -->
      <van-cell-group>
        <van-cell title="招生来源" :value="source" />
      </van-cell-group>
      <!-- end -->

      <!-- 介绍人 sponsors -->
      <van-cell-group>
        <van-cell title="介绍人" :value="sponsor" />
      </van-cell-group>
      <!-- end -->

      <!-- 备注 -->
      <van-cell-group>
        <van-cell title="备注" :value="message" />
      </van-cell-group>
    </div>
  </div>
</template>

<script>
import { OrderForm } from "../../../assets/js/api/user";
import {
  drivingSchool,
  findCoach,
  AllBanks,
  nativePlace,
  Introducer
} from "../../../assets/js/api/apply";
export default {
  name: "CheckOrder",
  data() {
    return {
      radio: "", // 是否本地
      type: "", // 申请类型
      drivingLicence: "", // 现有驾照
      ChooseSt: "", // 选择驾校
      coach: "", // 章教练
      override: "", // 准驾车型
      banks: "", // 班型
      text: "", // 姓名
      nationality: "", // 国籍
      papersType: "", // 证件类型
      IDCard: "", //证件号码
      set: "", // 性别
      years: "", // 出生日期
      site: "", // 身份证地址
      building: "", // 居住地
      residencePermit: "", // 居住证号
      cardTime: "", // 居住证签发时间
      stayExpire: "", // 暂住证到期时间
      signUpTime: "", // 报名时间
      source: "", // 招生来源
      sponsor: "", // 介绍人
      message: "", // 备注

      // 因为要显示驾校的名字和教练的名字，所以需要查询所有驾校和这个驾校对应的所有教练
      School: [], // 驾校
      corade: [], // 教练
      id: "", // 驾校的id
      arrBank: [], // 全部班型
      citizenship: [], // 国籍下拉
      sponsors: [], // 介绍人
      banksList: [] // 班型列表
    };
  },

  mounted() {
    // new Promise(function(resolve) {
    //   drivingSchool().then(res => {
    //     this.School = res.data;
    //   });
    //   resolve();
    // }).then(function() {
    //   this.trigger();
    // });

    drivingSchool().then(res => {
      // console.log(res);
      this.School = res.data;
      nativePlace().then(res => {
        // console.log(res);
        this.citizenship = res.data;
        findCoach().then(res => {
          // console.log(res);
          this.corade = res.data;
          this.trigger();
        });
      });
    });
  },

  methods: {
    trigger() {
      OrderForm().then(res => {
        // console.log(res);
        let details = res.data;
        // console.log(details);
        if (details.jsrly == "1") {
          this.radio = "本地";
        } else {
          this.radio = "外地";
        }
        if (details.ywlx == "1") {
          this.type = "初次申请";
        } else {
          this.type = "增加";
        }
        this.drivingLicence = details.yjcx;
        /**
         * 选择驾校
         */
        // 选择教练
        this.override = details.bmcx; // 准驾车型

        this.text = details.name; //  姓名
        //papersType  证件类型
        switch (details.cardtype) {
          case "1":
            this.papersType = "身份证";
            break;
          case "2":
            this.papersType = "护证";
            break;
          case "3":
            this.papersType = "港澳台身份证";
            break;
          case "4":
            this.papersType = "军官证";
            break;
        }
        this.IDCard = details.idcard; // 证件号码
        // 性别 set 0：男，1：女
        if (details.sex == "0") {
          this.set = "男";
        } else {
          this.set = "女";
        }
        this.years = details.birth; // 出生年月
        this.site = details.idcardAddress; // 身份证地址
        this.building = details.address; // 居住证
        this.residencePermit = details.jzzcode; // 居住证号
        this.cardTime = details.jzzqftime; // 居住证签发时间
        this.stayExpire = details.zzz; // 暂住证到期时间

        this.signUpTime = details.createTime; // 报名时间
        // this.source = details.zsly; // 招生来源
        switch (details.zsly) {
          case "1":
            this.source = "自主报名";
            break;
          case "":
            this.source = "老学员介绍";
            break;
          case "4":
            this.source = "宣传彩页";
            break;
          case "5":
            this.source = "代理";
            break;
          case "6":
            this.source = "电视广告";
            break;
          case "7":
            this.source = "公交广告";
            break;
          case "8":
            this.source = "网络推广";
            break;
          case "9":
            this.source = "其它";
            break;
        }
        // 介绍人 sponsors
        this.message = details.remarks; // 备注

        // 驾校

        for (let i = 0; i < this.School.length; i++) {
          if (this.School[i].id === details.jgbh) {
            this.id = this.School[i].id;
            this.ChooseSt = this.School[i].name;
            // 班型
            AllBanks(this.id, this.override).then(res => {
              // console.log(res);
              this.arrBank = res.data;
              // console.log(this.arrBank);
              for (let i = 0; i < this.arrBank.length; i++) {
                if (this.arrBank[i].id === details.bz) {
                  this.banks = this.arrBank[i].stageName; // 班型
                }
              }
            });
          }
        }

        // 教练
        for (let i = 0; i < this.corade.length; i++) {
          if (this.corade[i].drillId === details.yxjl) {
            this.coach = this.corade[i].name;
            // console.log(this.coach);
          }
        }

        // 国籍
        for (let i = 0; i < this.citizenship.length; i++) {
          if (this.citizenship[i].dictValue === details.nationality) {
            this.nationality = this.citizenship[i].remarks;
          }
        }

        // AllBanks(this.id, this.override).then(res => {
        //   this.banksList = res.data;
        // });

        // // 班型
        // for (let i = 0; i < this.banksList.length; i++) {
        //   if (this.banksList[i].id === details.bz) {
        //     this.banks = this.banksList[i].stageName;
        //   }
        // }
        // console.log(this.id);
        Introducer(this.id).then(res => {
          // console.log(res);
          if (res.code == 0) {
            this.sponsors = res.data;
            // 介绍人
            for (let i = 0; i < this.sponsors.length; i++) {
              if (this.sponsors[i].id === details.jsr) {
                this.sponsor = this.sponsors[i].name;
              }
            }
          }
        });
      });
    },

    onClickLeft() {
      this.$router.go(-1);
    }
  },
  created() {
    let dsBridge = require("dsbridge");
    dsBridge.call("goBack", "", function() {
      history.go(-1);
    });
  }
};
</script>

<style></style>
